from langchain_openai import ChatOpenAI
from langdev_helper.llm.qwen import llm
from langdev_helper.prompt.tale \
    import system_prompt, prompt_conf, prompt_tale_name, \
    prompt_tale_write, prompt_tale_outline

from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system", system_prompt
        ),
        MessagesPlaceholder(variable_name="messages"),
    ]
)
generate = prompt | llm

user_pormpt = prompt_tale_write
user_pormpt = prompt_tale_outline

essay = ""
messages = [
    HumanMessage(content=user_pormpt),
]

print(prompt)
print(messages)

# tale_name = generate.invoke({"messages": messages})
# tale_name = generate.invoke(messages)
# print(tale_name)

for chunk in generate.stream({"messages": messages}):
    print(chunk.content, end="")
    essay += chunk.content

